package redis.inaction.ratelimiter.filter.ratelimit;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import redis.inaction.ratelimiter.support.RouteApiUtils;

public class ApiKeyResolver implements KeyResolver {

    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        return Mono.just(exchange.getRequest().getPath().toString());
    }

    public Mono<String> resolve(ServerWebExchange exchange, String apiCodeName) {
       return Mono.just(RouteApiUtils.getApiCode(exchange, apiCodeName));
    }
}
